import Vue from 'vue'
import VueRouter from 'vue-router'

// import Login from '@/views/login/Login'
// import Home from '@/views/home/Home'
// import welcome from '@/views/home/homeChildren/welcome'
// import welcome from '@/views/home/homeChildren/homeMainChildren/users'
// import Rights from '@/views/home/homeChildren/homeMainChildren/rights/Rights'
// import Roles from '@/views/home/homeChildren/homeMainChildren/rights/Roles'

const Login = () => import('@/views/login/Login')
const Home = () => import('@/views/home/Home')
const users = () => import('@/views/home/homeChildren/homeMainChildren/users')
const welcome = () => import('@/views/home/homeChildren/welcome')
const Rights = () => import('@/views/home/homeChildren/homeMainChildren/rights/Rights')
const Roles = () => import('@/views/home/homeChildren/homeMainChildren/rights/Roles')
const Cate = () => import('@/views/home/homeChildren/homeMainChildren/goods/Cate')
const Params = () => import('@/views/home/homeChildren/homeMainChildren/goods/Params')
const List = () => import('@/views/home/homeChildren/homeMainChildren/goods/List')
const Add = () => import('@/views/home/homeChildren/homeMainChildren/goods/Add')
const Orders = () => import('@/views/home/homeChildren/homeMainChildren/order/Order')

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/welcome'
    },
    {
        path: '/Login',
        name: 'Login',
        component: Login,
    },
    {
        path: '/Home',
        component: Home,
        redirect: '/welcome',
        children: [{
                path: '/welcome',
                component: welcome
            },
            {
                path: '/users', 
                component: users
            },
            {
                path: '/rights',
                component: Rights
            },
            {

                path: '/roles',
                component: Roles
            },
            {
                path: '/categories',
                component: Cate
              },
              {
                path: '/params',
                component: Params
              },
              {
                path: '/goods',
                component: List
              },
              {
                path: '/goods/add',
                component: Add
              },
              {
                path: '/orders',
                component: Orders
              },
        ]
    }
]
// 创建一个路由器来管理整个vue项目中的所有路由
const router = new VueRouter({
    routes,
    mode: 'history'
})
// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//     //to将要访问的路径 from代表从哪个路径离开 next函数表示放行 next() / next('/login')强制跳转
//     if (to.path == '/Login') return next();
//     const tokenArr = window.sessionStorage.getItem('token')
//     if (tokenArr) {
//         next()
//     } else {
//         next('/login')
//     }
// })
// 导出router
export default router